﻿//        Another Demo from Andy L. & MissedMemo.com
// Borrow whatever code seems useful - just don't try to hold
// me responsible for any ill effects. My demos sometimes use
// licensed images which CANNOT legally be copied and reused.

using System;
using System.Windows;
using System.Collections.Generic;

using MissedMemo.MeatAndCheeseDisc.BusinessLogic;


namespace MissedMemo.MeatAndCheeseDisc.OrderMonitor
{
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
        }


        private void OnSimulateNewOrder( object sender, RoutedEventArgs e )
        {
            KitchenOrder order = new KitchenOrder( CreateDemoPizza() );

            App.KitchenOrders.Add( order );
            UpdateHintVisibility();
        }


        private void OnOrderItemCompleted( object sender, System.Windows.Input.ExecutedRoutedEventArgs e )
        {
            FrameworkElement item = e.OriginalSource as FrameworkElement;

            if( item != null )
            {
                KitchenOrder order = item.DataContext as KitchenOrder;

                if( order != null )
                {
                    App.KitchenOrders.Remove( order );
                    UpdateHintVisibility();
                }
            }
        }


        // Quick ugly hack, just to generate some semi-random data
        private Pizza CreateDemoPizza()
        {
            Random rand = new Random();

            Pizza pizza = new Pizza();
            
            // Random PizzaType
            Array values = Enum.GetValues( typeof( PizzaType ) );
            int i = rand.Next( values.Length );

            pizza.ItemType = (PizzaType)values.GetValue( i );

            // Random PizzaSize
            values = Enum.GetValues( typeof( PizzaSize ) );
            i = rand.Next( values.Length );

            pizza.Size = (PizzaSize)values.GetValue( i );

            return pizza;
        }


        private void UpdateHintVisibility()
        {
            if( App.KitchenOrders.Count == 0 )
                labelHint.Visibility = Visibility.Visible;
            else
                labelHint.Visibility = Visibility.Hidden;
        }
    }
}
